#include <iostream>
#include <fstream>
#include <vector>

bool isPrime(int x) {
    if(x < 2)   return false;
    for(int i=2; i*i<=x; i++)
        if(x % i == 0)
            return false;
    return true;
}

// 生成输入数据并写入文件
void writeInputData(const std::string& filename, int x, int y) {
    std::ofstream outFile(filename);
    if(outFile) {
        outFile << x << " " << y << "\n";
        outFile.close();
    } else {
        std::cerr << "Error opening file: " << filename << std::endl;
    }
}

// 生成输出数据（在此简单计算输入数的和）并写入文件
void writeOutputData(const std::string& filename, int result) {
    std::ofstream outFile(filename);
    if(outFile) {
        outFile << result << "\n";
        outFile.close();
    } else {
        std::cerr << "Error opening file: " << filename << std::endl;
    }
}

int main() {
    std::string name = "smile";
    std::vector<std::pair<int, int>> testData = {
        {2, 2},
        {4, 6},
        {5, 10},
        {10, 13},
        {17, 19},
        {10, 20},
        {1, 20},
        {10, 50},
        {100, 200},
        {1, 1000}
    };

    for(size_t i = 0; i < testData.size(); ++i) {
        std::string inputFilename = name + std::to_string(i + 1) + ".in";
        std::string outputFilename = name + std::to_string(i + 1) + ".out";
        
        // 写入输入数据
        const auto& [x, y] = testData[i];
        writeInputData(inputFilename, x, y);
        
        // 计算输出数据（这里是 x + y）
        int result = 0;
        for(int i=x; i<=y; i++)
            if(isPrime(i))  result++;
        // 写入输出数据
        writeOutputData(outputFilename, result);
    }

    std::cout << "Input and Output data files generated successfully!" << std::endl;
    return 0;
}